package cn.dansj.repository;

import cn.dansj.entity.Article;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ArticleRepository extends JpaRepository<Article, String>, JpaSpecificationExecutor<Article> {
    Article getArticleBySequence(String sequence);

    int deleteArticleBySequence(String sequence);

    @Query("select t from Article t where t.status=1 order by t.crtTime desc")
    List<Article> getList();

    @Query("select t.type,count(t) from Article t where t.status=1 group by t.type order by 2 desc")
    List<Object[]> category();

    @Query("select t from Article t where t.status=1 and (t.title like concat('%',:keyword,'%') or t.description like concat('%',:keyword,'%'))")
    List<Article> search(@Param("keyword") String keyword);
}
